﻿using System;

namespace SimpleSim.SimEngine
{
    public class AnalogTag
    {
        public string Name { get; private set; }

        public string Description { get; set; }

        private double _value;
        public double Value
        {
            get { return _value; }
            set
            {
                if (value < 0)
                    _value = 0;
                else if (value > 1)
                    _value = 1;
                else
                    _value = value;
            }
        }

        public double RawHigh { get; set; }
        public double RawLow { get; set; }
        public double RawValue
        {
            get { return (Value*(RawHigh - RawLow)) + RawLow; }
            set { Value = (value - RawLow)/(RawHigh - RawLow); }
        }

        public double EngHigh { get; set; }
        public double EngLow { get; set; }
        public double EngValue
        {
            get { return (Value * (EngHigh - EngLow)) + EngLow; }
            set { Value = (value - EngLow) / (EngHigh - EngLow); }
        }

        public AnalogTag()
        {
            RawHigh = 100;
            RawLow = 0;
            EngHigh = 100;
            EngLow = 0;
        }


        public bool SetRawValue(double rawValue)
        {
            RawValue = rawValue;
            return true;
        }

        public bool SetEngValue(double engValue)
        {
            EngValue = engValue;
            return true;
        }
    }

}
